
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/17 0017
  Time: 下午 3:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" action="/shop/saveAgent">
    <input  name="id" value="${id}" type="hidden">
    <input type="hidden" value="${memberId}" name="memberId">
    <input type="hidden" value="${faceValueId}" name="faceValueId">

    <div class="layui-form-item">
        <label class="layui-form-label ">卡种</label>
        <div class="layui-form-mid layui-word-aux">${commodit.name}</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">面值</label>
        <div class="layui-form-mid layui-word-aux">${faceValue.faceValue}</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">返利率</label>
        <div class="layui-input-block">
            <input type="number" name="rebatesThan" required oninput="onInput()" id="id1"
                   placeholder="请输入返利率" autocomplete="off" class="layui-input" value="${record.rebatesThan}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">返利金额</label>
        <div class="layui-input-block">
            <input type="number" name="rebatesThan" required id="id2"
                   placeholder="自动计算返利金额" autocomplete="off" class="layui-input" value="${record.rebatesThan}">
        </div>
    </div>

    <script>

        function onInput() {

           var id1v=$("#id1").val();

           var money=${faceValue.faceValue};


            $("#id2").val(id1v*money);

        }


    </script>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <%--<button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
        </div>
    </div>
</form>

<script>

    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {

            console.log(data.field);
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: '/shop/saveAgent',
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: data.field,
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend: function (xhr) {
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success: function (data) {

                    if (data.result) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);

                    } else {
                        layer.msg(data.msg, {time: 2000, icon: 5});
                    }
                    //console.log(data)
                },
                error: function (xhr, textStatus) {
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete: function () {
                    //console.log('结束')
                }
            });
            return false;
        });
    });
</script>


</body>
</html>
